<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>添加文章</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="后台管理">
<meta name="description" content="后台管理">
<meta name="author" content="yinqi">
<link href="../plugin/admin/css/bootstrap.min.css" rel="stylesheet">
<link href="../plugin/admin/css/materialdesignicons.min.css"
	rel="stylesheet">
<!--标签插件-->
<link rel="stylesheet"
	href="../plugin/admin/js/jquery-tags-input/jquery.tagsinput.min.css">
<link href="../plugin/admin/css/style.min.css" rel="stylesheet">
</head>

<body>
	<div class="container-fluid p-t-15">

		<div class="row">
			<div class="col-lg-12">
				<div class="card">
					<div class="card-body">

						<form action="#!" method="post" class="row">
							<div class="form-group col-md-12">
								<label for="title">标题</label> <input type="text"
									class="form-control" id="title" name="title" value=""
									placeholder="请输入标题" />
							</div>
							<div class="form-group col-md-12">
								<label for="seo_keywords">作者</label> <input type="text"
									class="form-control" id="author" name="author" value=""
									placeholder="请输入作者" />
							</div>
							<div class="form-group col-md-12">
								<label for="seo_description">状态</label> <input
									class="form-control" id="state" name="state" value=""
									placeholder="状态值为1或者0" />
							</div>
							<div class="form-group col-md-12">
								<label>图片上传</label>
								<div class="form-controls">

									<ul class="list-inline clearfix lyear-uploads-pic">
										<li class="col-xs-4 col-sm-3 col-md-2"><input id="Upload"
											type="file" name="Upload" /></li>
									</ul>
								</div>
							</div>
							<div class="form-group col-md-12">
								<label for="content">内容</label>
								<textarea name="details" id="details" style="height: 800px;"></textarea>
							</div>
							<div class="form-group col-md-12">
								<button type="button" class="btn btn-primary ajax-post" id="add"
									onclick="addBlog();">确 定</button>
								<button type="button" class="btn btn-default"
									onclick="javascript:history.back(-1);return false;">返
									回</button>
							</div>
						</form>

					</div>
				</div>
			</div>

		</div>

	</div>

	<script type="text/javascript" src="../plugin/admin/js/jquery.min.js"></script>
	<script type="text/javascript"
		src="../plugin/admin/js/bootstrap.min.js"></script>
	<!--标签插件-->
	<script
		src="../plugin/admin/js/jquery-tags-input/jquery.tagsinput.min.js"></script>
	<script type="text/javascript" src="../plugin/admin/js/main.min.js"></script>
	<script src="../plugin/ckeditor/ckeditor.js"></script>
	<!-- 消息通知 -->
	<script src="../plugin/admin/js/bootstrap-notify.min.js"></script>
	<script type="text/javascript" src="../plugin/admin/js/lightyear.js"></script>
	<script type="text/javascript">
		$(function() {
			CKEDITOR.replace('details');

		});
		addBlog = function() {
			alert("666进来了");
			var formData = new FormData();
			formData.append('upload', $('#Upload')[0].files[0]); //添加图片信息的参数
			//alert(formData)
			$.ajax({
				type : "POST",
				url : "../basefile/uploadImage",
				data : formData,
				contentType : false,
				processData : false,
				dataType : "json",
				success : function(data) {
					console.log(data["url"])
					var path = data["url"];
					$.ajax({
						url : '../blog/saveBlog',
						type : 'POST',
						dataType : "json",
						data : {
							author : $("#author").val(),
							title : $("#title").val(),
							details : CKEDITOR.instances.details.getData(),
							path : path,
							state : $("#state").val()
						},
						success : function(obj) {
							//alert("88888小伟");
							if (obj.result == 1) {
								lightyear.loading('show');
								// 假设ajax提交操作
								setTimeout(function() {
									lightyear.loading('hide');
									lightyear.notify('添加成功!', 'success', 1000);
								}, 1e3), setTimeout(function() {
									window.location.reload();
								}, 3000)
							}
						}
					});

				}
			});

		}
	</script>
</body>
</html>